﻿using System;
using System.Linq;

namespace Diploma.Models
{
    public partial class GlobalTask : ISoftDeletable
    {
        #region ISoftDeletable Members

        public void MarkForDeletion()
        {
            Mark(true);
        }

        public void UnmarkFromDeletion()
        {
            Mark(false);
        }

        #endregion

        protected void Mark(bool asDeleted)
        {
            DeletionDate = asDeleted ? (DateTime?) DateTime.Now : null;
            GlobalTasksCompletions.ToList().ForEach(delegate(GlobalTasksCompletion gtc)
                                                        {
                                                            if (asDeleted) gtc.MarkForDeletion();
                                                            else gtc.UnmarkFromDeletion();
                                                        });
            Tasks.ToList().ForEach(delegate(Task t)
                                       {
                                           if (asDeleted) t.MarkForDeletion();
                                           else t.UnmarkFromDeletion();
                                       });
        }
    }
}